package com.crazyhat.crazyhat.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crazyhat.crazyhat.attribute.ClubPositionEnum;
import com.crazyhat.crazyhat.dto.ClubMemberDTO;
import com.crazyhat.crazyhat.entity.Participation;
import com.crazyhat.crazyhat.pojo.Result;
import com.crazyhat.crazyhat.service.IParticipationService;

/**
 * <p>
 * 参与的社团 前端控制器
 * </p>
 *
 * @author crazyhat
 * @since 2024-07-05
 */
@RestController
@RequestMapping("/participation")
public class ParticipationController {

    @Autowired
    IParticipationService participationService;

    /**
     * 判断用户是否已参与社团
     * @param clubId
     * @param studentId
     * @return
     */
    @GetMapping("/ParticipationState")
    public Result<Boolean> getParticipationState(
        @RequestParam(value = "clubId") Integer clubId,
        @RequestParam(value = "studentId") Integer studentId) {
        return Result.success(participationService.hasParticipation(clubId, studentId));
    }
    

    /**
     * 获取个人参与的社团
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/personalParticipation")
    public Result<Page<Participation>> getPersonalParticipation(@RequestParam int pageNum, @RequestParam int pageSize) {

        Page<Participation> participationPage = participationService.getParticipation(pageNum, pageSize);
        return Result.success(participationPage);
    }

    /**
     * 获取用户的相应的社团职位
     * @param clubId
     * @return
     */
    @GetMapping("/clubPosition")
    public Result<ClubPositionEnum> getclubPositionOfUser(@RequestParam("clubId") Integer clubId) {
        
        return Result.success(participationService.getclubPositionOfUser(clubId));
    }

    /**
     * 获取社团成员列表
     * @param clubId
     * @return
     */
    @GetMapping("/clubMemberList")
    public Result getClubMemberList(@RequestParam("clubId") Integer clubId) {
        
        List<ClubMemberDTO> clubMemberList=participationService.getClubMemberList(clubId);

        if (clubMemberList!=null) {
            return Result.success(clubMemberList);
        } else {
            return Result.error("获取社团成员列表失败");
        }
    }
    
    
}
